<!--
 * @Description: 新闻咨询- article_news
 * @Author: your name
 * @Date: 2023-12-06
 * @LastEditTime: 2023-12-06
 * @LastEditors: Please set LastEditors
-->

<template>
  <div>
    <div class="article_news heart_w">
      <div class="main">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane
            :label="item.name"
            :value="item"
            :name="String(i)"
            v-for="(item, i) in dataTabs"
            :key="item.id"
          ></el-tab-pane>
        </el-tabs>

        <div
          class="tabs-content"
          v-if="activeName == dataTabs[activeName]?.id - 1"
        >
          <a
            href="javascript:void(0);"
            v-for="item_a in advisory"
            :key="item_a.type_id"
            class="zixun"
          >
            <el-image :src="item_a.image"></el-image>
            <div class="consult_list">
              <h3 class="title">{{ item_a.type_name }}</h3>
              <p v-for="item_t in item_a.list" :key="item_t.id">
                <a
                  :href="`#/articleDetails?id=${item_t.id}&type_id=${item_a.type_id}`"
                  target="_blank"
                >
                  {{ item_t.title }}
                </a>
              </p>
              <a
                :href="`#/consult/examCourse?id=${item_a.type_id}&tabIds=${zixunId}`"
                class="moreadd"
                target="_blank"
              >
                More+
              </a>
            </div>
          </a>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getCateData, getNewsList } from '@/api/homePage.js'

export default {
  name: 'article_news',
  data() {
    return {
      dataTabs: [],
      advisory: [],
      activeName: '0',
      zixunId: 1
    }
  },
  created() {
    getCateData().then((res) => {
      this.dataTabs = res.data.data
    })

    this.getArticleData(this.zixunId)
  },
  methods: {
    getArticleData(cateId) {
      getNewsList({ cate: cateId, type: 1 }).then((res) => {
        this.advisory = res.data.data
      })
    },
    handleClick(el) {
      this.zixunId = el.$attrs.value.id
      this.getArticleData(el.$attrs.value.id)
    }
  }
}
</script>

<style scoped lang="scss">
.article_news {
  margin-top: 20px;
  margin-bottom: 100px;
}

.main {
  background-color: #fff;
  border-radius: 8px;

  ::v-deep .el-tabs__active-bar {
    height: 3px;
    background-color: #2c8eff;
  }

  .el-tabs__item.is-active {
    color: #409eff !important;
  }

  ::v-deep .el-tabs__nav-wrap::after {
    height: 1px;
    background-color: #e1e1e1;
  }

  ::v-deep .el-tabs__header {
    margin: 0;
    background-color: #fff;
    border-radius: 8px;
  }

  ::v-deep .el-tabs__nav-wrap {
    padding: 0 30px;
  }

  ::v-deep .el-tabs__item {
    height: 68px;
    overflow: hidden;
    font-size: 16px;
    line-height: 68px;
    text-align: center;
    color: #666;
    user-select: none;
  }
}

.tabs-content {
  .zixun {
    display: flex;
    padding: 25px;
    border-top: 1px solid #f1f1f1;
  }
  .consult_list {
    p {
      a {
        font-size: 14px;
        color: #333;
        text-overflow: ellipsis;
        line-height: 22px;
        overflow: hidden;
        white-space: nowrap;
        width: 100%;
        display: inline-block;

        &:hover {
          color: #ff6b00;
        }
      }
    }
  }

  .title {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 8px;
  }

  .el-image {
    width: 255px;
    height: 170px;
    border-radius: 8px;
    ::v-deep .el-image__inner {
      transition: 0.5s all ease;
    }
    ::v-deep .el-image__inner:hover {
      transform: scale(1.1);
      transition: 0.5s all ease;
    }
  }

  .el-image + div {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-width: 0;
    padding: 5px 0 10px;
    margin-left: 27px;
    color: #111;
    flex: 1;

    .moreadd {
      text-align: right;
      font-size: 15px;
      transition: 0.5s all ease;
      color: #333;
      line-height: 28px;

      &:hover {
        text-decoration: underline;
        transition: 0.5s all ease;
        font-size: 20px;
      }
    }
  }
}
</style>
